package ru.braim.weather_app.models;

import jakarta.persistence.*;
import lombok.Getter;
import ru.braim.weather_app.utils.validators.EmailValidator;

import java.util.List;

@Getter
@Entity
public class Account {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(nullable = false)
    private String firstName;

    @Column(nullable = false)
    private String lastName;

    @Column(nullable = false, unique=true)
    private String email;

    @Column(nullable = false)
    private String password;

    @Column(nullable = false, unique=true)
    private String cookie;

    @Column(nullable = false)
    private String salt;

    @OneToMany(mappedBy = "account", cascade = CascadeType.ALL)
    private List<Region> regions;


    public boolean setFirstName(String firstName) {
        if (firstName == null) {
            return false;
        }
        if (firstName.isBlank()) {
            return false;
        }
        this.firstName = firstName;
        return true;
    }

    public boolean setLastName(String lastName) {
        if (lastName == null) {
            return false;
        }
        if (lastName.isBlank()) {
            return false;
        }
        this.lastName = lastName;
        return true;
    }

    public boolean setEmail(String email) {
        if (email == null) {
            return false;
        }
        if (!EmailValidator.validateEmail(email)) {
            return false;
        }
        this.email = email;
        return true;
    }

    public boolean setPassword(String password) {
        if (password == null) {
            return false;
        }
        if (password.isBlank()) {
            return false;
        }
        this.password = password;
        return true;

    }

    public boolean setSalt(String salt) {
        if (salt == null) {
            return false;
        }
        if (salt.isBlank()) {
            return false;
        }
        this.salt = salt;
        return true;

    }

    public boolean setCookie(String cookie) {
        if (cookie == null) {
            return false;
        }
        if (cookie.isBlank()) {
            return false;
        }
        this.cookie = cookie;
        return true;
    }

}
